# -*- coding: utf-8 -*-
"""
__mktime__ = '2019/4/14'
__author__ = 'Just'
__filename__ = 'mh_latest'
"""
from sqlalchemy import Column, Integer, String, orm, ForeignKey, desc
from app.model.base import BaseModel, db


class ComicLatest(BaseModel):
    """漫画最近更新模型"""
    __tablename__ = 'comic_latest'

    id = Column(Integer, primary_key=True, autoincrement=True)
    state = Column(String(6), comment='连载状态')
    update_time = Column(Integer, comment='最近更新时间')
    latest = Column(String(255), comment='漫画最新章节')
    cid = Column(Integer, ForeignKey('comic.cid'), nullable=False, comment='漫画id')
    # 一对一 一个更新条目对应一部漫画
    comic = db.relationship('Comic')

    @orm.reconstructor
    def __init__(self):
        # 序列化列表
        self.fields = ['cid', 'state', 'latest', 'update_time']

    @staticmethod
    def get_hot_midlist():
        """查找最近 10本 更新的书籍id列表"""
        latest_data = ComicLatest.query.order_by(desc(ComicLatest.update_time), ComicLatest.status==1).limit(10).all()
        return latest_data
